{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# _Modeling of Qubit Chain_\n",
    "\n",
    "<img src=\"images/line_qubits.png\" alt=\"Qubit Chain\">\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Contributor\n",
    "Alexander Yu. Vlasov\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The model may be illustrated using images from composer.\n",
    "First image is for one step of quantum walk. \n",
    "Each step uses two partitions described earlier.\n",
    "For five qubits each partition includes two two-qubit gates denoted here as m1 and m2\n",
    "\n",
    "<img src=\"images/qx_quchain.png\" alt=\"Q-Walk Firts Step\">\n",
    "\n",
    "Two (or more) steps of quantum walk should repeat the sequences of gates described above \n",
    "\n",
    "<img src=\"images/qx_quchain_t2.png\" alt=\"Q-Walk Two Steps\">\n",
    "\n",
    "The program below uses QISKit with the similar purposes.\n",
    "\n",
    "Parameter `n_nodes` is used for number of nodes and should be odd due to implementation of partitions.\n",
    "\n",
    "Parameter `n_step` is number of steps.\n",
    "\n",
    "Boolean parameter `hist` provides two method of simulation. \n",
    "The example below uses `hist = True`. \n",
    "In such a case simulator produces probabilities of different outcomes with `qasm_simulator` backend. \n",
    "The `hist = False` uses `statevector_simulator` backend to calculate amplitudes.\n",
    "It may be useful sometimes, but `unitary_simulator` may be more convenient \n",
    "(see link and comments below).\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "COMPLETED\n"
     ]
    }
   ],
   "source": [
    "from pprint import pprint\n",
    "import math\n",
    "import numpy as np\n",
    "\n",
    "# importing the Qiskit\n",
    "from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister\n",
    "from qiskit import Aer, execute\n",
    "# import state tomography functions\n",
    "from qiskit.tools.visualization import plot_histogram, plot_state\n",
    "\n",
    "# Definition of matchgate\n",
    "\n",
    "def gate_mu3(qcirc,theta,phi,lam,a,b):\n",
    "    qcirc.cx(a,b)\n",
    "    qcirc.cu3(theta,phi,lam,b,a)\n",
    "    qcirc.cx(a,b)\n",
    "    \n",
    "# Number of qubits (should be odd)\n",
    "n_nodes = 5 \n",
    "\n",
    "# Number of steps\n",
    "n_step = 2\n",
    "\n",
    "# Histogram\n",
    "hist = True\n",
    "# Quantum Sphere\n",
    "# hist = False\n",
    "\n",
    "\n",
    "# Creating Registers\n",
    "qr = QuantumRegister(n_nodes) \n",
    "cr = ClassicalRegister(n_nodes)\n",
    "\n",
    "# Creating Circuits\n",
    "qc = QuantumCircuit(qr,cr)\n",
    "\n",
    "# Initial state\n",
    "qc.x(qr[0])\n",
    "\n",
    "# Creating of two partitions with M1' and M2\n",
    "# Repeating that n_step times\n",
    "\n",
    "for k in range(0,n_step):\n",
    "    for i in range(0,n_nodes-1,2):\n",
    "        gate_mu3(qc,math.pi, math.pi, 0, qr[i], qr[i+1])\n",
    "    for i in range(1,n_nodes,2):\n",
    "        gate_mu3(qc,math.pi/2, 0, 0, qr[i], qr[i+1])\n",
    "\n",
    "if hist:\n",
    "    for i in range(0,n_nodes):\n",
    "        qc.measure(qr[i], cr[i])\n",
    "\n",
    "\n",
    "# To print the circuit  \n",
    "# QASM_source = qc.qasm()\n",
    "# print(QASM_source)\n",
    "\n",
    "\n",
    "if hist:\n",
    "    backend = 'qasm_simulator' \n",
    "    shots = 4096\n",
    "else:\n",
    "    backend = 'statevector_simulator' \n",
    "    shots = 1   # amplitudes instead of probabilities\n",
    "    \n",
    "job = execute(qc, Aer.get_backend(backend), shots = shots ) # Execute quantum walk \n",
    "result = job.result()\n",
    "\n",
    "print(result)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The result of simulation represented below as histogram if `hist=True` \n",
    "(or as Quantum Sphere if `hist=False`)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0K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8GtnLZXuNA4GvAd4G7SIsBnQx8Q9JnSNPs7F5akTXkLqYeyk5A/gvwn8BDkh4hXfNwB2kOpmbgxBJLtDrzZ8BInWuXkS6WvQ+4J9tjOIh0qPGtwDtJJ6j7PJ+D2ATZYuSTSMed30z6gpgbEZeWWpgVxp+BrVvFTL6qXC0uW372KxGxS4nl1YwDYjNlbW4DIuKFsmuxcvgzYBUzun6JtBb9v5ZdUy04IMzMakTSrsBfssWi+jwHhJmZ5XIXk5mZ5XJAmJlZLgeEmZmSjS6lAAAAGElEQVTlckCYmVkuB4SZmeVyQJiZWa7/A+10gAZz4dFfAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fa0bc2990b8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "if hist:\n",
    "    plot_histogram(result.get_counts(qc))\n",
    "else:    \n",
    "    data_ampl = result.get_data(qc)\n",
    "    state_walk = data_ampl['statevector']\n",
    "    rho_walk = np.outer(state_walk,state_walk.conj())\n",
    "    plot_state(rho_walk,'qsphere')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "The correct result should represent nonzero values only for states with one unit in computational basis.\n",
    "It may be illustrative to use Quantum Sphere for such a data. Such a representation for\n",
    "_many steps_ of quantum walk is shown in [next notebook](qubit_chain_mod_many.ipynb).\n",
    "However trick used there is _only for simulations_. "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
